020114: This REALLY REALLY must be cleaned up...
021231: Not yet, but soon, it will only be a question of removing commented
out stuff... Hopefully...
050120: Changed return types for boolean functions from int to bool.
Hope this doesn't break anything.
*/
template
class vector3t
{
public:
T coo[3];
vector3t()
{
coo[0]=0.0;
coo[1]=0.0;
coo[2]=0.0;
};
vector3t(const T a, const T b, const T c)
{
coo[0]=a;
coo[1]=b;
coo[2]=c;
}
vector3t(const float *a)
{
coo[0]=a[0];
coo[1]=a[1];
coo[2]=a[2];
}
vector3t(const double *a)
{
coo[0]=a[0];
coo[1]=a[1];
coo[2]=a[2];
}
// 030819: Disse to 鴇elegger et eller annet. Fordi de erstatter en default (og bitwise) copy constructor, uten at de samtidig er gode nok til ?gj鴕e det??? Skj鴑ner ikke helt hva som skjer... M?sjekkes opp... @@@
// vector3t(vector3t
// {
// coo[0]=v0.x();
// coo[1]=v0.y();
// coo[2]=v0.z();
// }
// vector3t(vector3t
// {
// coo[0]=v0.x();
// coo[1]=v0.y();
// coo[2]=v0.z();
// }
~vector3t(void) {}
// vector rotate2d(T,int);
// vector transform(coo_system &);
//
// 010122: For fast access used in OpenGL:
//
inline const T *raw(void) const
{
return coo;
}
//
// 010125
// 021024: Added the reference-versions.
//
inline T x(void) const { return coo[0]; }
inline T y(void) const { return coo[1]; }
inline T z(void) const { return coo[2]; }
inline T &x(void) { return coo[0]; }
inline T &y(void) { return coo[1]; }
inline T &z(void) { return coo[2]; }
//
// 010207
//
inline void setx(const T a) { coo[0]=a; }
inline void sety(const T a) { coo[1]=a; }
inline void setz(const T a) { coo[2]=a; }
//
// Check out this on gcc... Why does only SGI CC complain?
//
inline bool operator==(const vector3t &v) const
{
return ((coo[0]==v.coo[0]) && (coo[1]==v.coo[1]) && (coo[2]==v.coo[2]));
}
//
// 050120: Adding this... Would also be nice with one "and"'ing the
// results on each component... No, not necessary...
// Remember that deMorgan gives that a<&b <=> !(a>|b).
//
inline bool operator<(const vector3t &v) const
{
return ((coo[0]
inline bool operator>(const vector3t &v) const
{
return ((coo[0]>v.coo[0]) || (coo[1]>v.coo[1]) || (coo[2]>v.coo[2]));
}
//
// Note: Prefer a!=b to !(a==b) since the former is probably faster!
//
inline bool operator!=(const vector3t &v) const
{
return ((coo[0]!=v.coo[0]) || (coo[1]!=v.coo[1]) || (coo[2]!=v.coo[2]));
}
//
// Ok, the strange warning produced when actually using this operator,
// stemmed from a missing 'const' at the end of the declaration of
// this operator. (Then the function could have altered *this, and
// that would have discarded any const'ness...)
//
inline const vector3t operator+(const vector3t &v) const
{
return vector3t(coo[0]+v.coo[0], coo[1]+v.coo[1], coo[2]+v.coo[2]);
}
inline vector3t &operator+=(const vector3t &v)
{
coo[0]+=v.coo[0]; coo[1]+=v.coo[1]; coo[2]+=v.coo[2];
return *this;
}
// 030819
// inline vector3t
// {
// coo[0]+=v.coo[0]; coo[1]+=v.coo[1]; coo[2]+=v.coo[2];
// return *this;
// }